import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class RemoveRepeat_LengthMAXup {

	public static BufferedReader bufread;
	public static BufferedWriter bufwrite;
	public static List<String> list = new ArrayList<String>();
	public static String filenamenotsort = "14I16CON.txt";

	public static List<String> Asortlist(String filename) throws IOException {
		bufread = new BufferedReader(new FileReader(filename));
		String s = bufread.readLine();
		do {
			if (!list.contains(s)) {
				list.add(s);
			}
			s = "";
			s = bufread.readLine();
		} while (s != null);
		bufwrite = new BufferedWriter(new FileWriter("sort" + filename));
		for (int j = 1; j < list.size(); j++) {
			for (int i = 0; i < (list.size() - j); i++) {
				if (list.get(i).length() < list.get(i + 1).length()) {
					String temp = list.get(i);
					list.set(i, list.get(i + 1));
					list.set(i + 1, temp);
				}
			}
		}
		for (int k = 0; k < list.size(); k++) {
			bufwrite.write(list.get(k) + "\n");
		}
		bufwrite.close();

		for (int k = 0; k < list.size(); k++) {
			System.out.println(list.get(k));
		}

//		List<String> listtemp = new ArrayList<String>();
		for (int dd = 0; dd < list.size(); dd++) {
			list.get(dd).split(",");
		}
		return list;
	}

	public static void main(String[] args) throws IOException {
		Asortlist(filenamenotsort);
		// for(int k=0;k<list.size();k++){
		// System.out.println(list.get(k));
		// }
	}

}
